package com.example.webproject.service.impl;

import com.example.webproject.entity.Course;
import com.example.webproject.entity.User;
import com.example.webproject.repository.CourseRepository;
import com.example.webproject.repository.UserRepository;
import com.example.webproject.service.CourseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author hhs
 * @Description
 * @date 2022/12/12 15:45
 */
@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseRepository courseRepository;


    /**
     * 通过id查询用户信息
     * @param id
     * @return
     */
    @Override
    public Course getCourse(Long id) {
        return courseRepository.findById(id).get();
    }

    /**
     * 查询用户列表
     * @return
     */
    @Override
    public List<Course> listCourse() {
        return courseRepository.findAll();
    }

    @Override
    public void saveCourse(Course course) {
        Course newCourse = new Course();
        BeanUtils.copyProperties(course,newCourse);
        courseRepository.save(newCourse);
    }

    @Override
    public Course updateCourse(Long id, Course course) {
        return null;
    }

    @Override
    public void deleteCourse(Long id) {

    }

}
